<?php

namespace App\Models;

class MoneyBookUser extends Model
{
    protected $table = 'money_book_users';

    protected $fillable = [
        'book_id',
        'user_id',
        'role', // admin: 管理员, member: 普通成员
    ];

    // 角色常量
    const ROLE_ADMIN = 'admin';
    const ROLE_MEMBER = 'member';

    /**
     * 获取关联的用户
     */
    public function user()
    {
        return $this->belongsTo(User::class);
    }

    /**
     * 获取关联的账本
     */
    public function book()
    {
        return $this->belongsTo(MoneyBook::class, 'book_id');
    }
}
